﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dukou.Example.DTO.Domain;
using Dukou.Example.DTO.DTO;
using Dukou.DTO;

namespace Dukou.Example.DTO.Parsers
{
    public class MemberCardParser : ObjectParser<MemberCardDTO, MemberCard>
    {
        protected override MemberCardDTO InternalParse(MemberCard k, IDictionary<string, ObjectCache> temp, int depth)
        {
            MemberCardDTO dto = new MemberCardDTO()
            {
                Id = k.Id,
                LocalId = Guid.NewGuid(),
                CardNumber = k.CardNumber
            };

            temp.Add(k.GetIdentity(), new ObjectCache(depth, dto));

            dto.Customer = ObjectParser.Parse<CustomerDTO, Customer, CustomerParser>(k.Customer, temp, depth - 1);
            //dto.Updator = ObjectParser.Parse<UserDTO, User, UserParser>(k.Updator, temp, depth - 1);

            return dto;
        }

        protected override MemberCard InternalParse(MemberCardDTO t, IDictionary<string, ObjectCache> temp, int depth)
        {
            MemberCard memberCard = new MemberCard()
            {
                Id = t.Id,
                CardNumber = t.CardNumber
            };

            temp.Add(t.GetIdentity(), new ObjectCache(depth, memberCard));

            memberCard.Customer = ObjectParser.Parse<CustomerDTO, Customer, CustomerParser>(t.Customer, temp, depth - 1);
            //user.Updator = ObjectParser.Parse<UserDTO, User, UserParser>(t.Updator, temp, depth - 1);

            return memberCard;
        }
    }
}
